$(function() {
	GetYourLocation();
});
function GetYourLocation() {
	$("#locationDes").html("正在获取位置......");

	var geolocation = new BMap.Geolocation();
	geolocation.getCurrentPosition(function(r) {
		if (this.getStatus() == BMAP_STATUS_SUCCESS) {
			var pt = new BMap.Point(r.point.lng, r.point.lat);
			var geoc = new BMap.Geocoder();
			geoc.getLocation(pt, function(rs) {// 解析格式：城市，区县，街道
				var addComp = rs.addressComponents;
				var s='<img width="5%" src="/wcsi/img/yourlocation.png"/>';
				$("#locationDes").html(s+
						addComp.city + "," + addComp.district + ","
								+ addComp.street + "," + addComp.streetNumber);
			});
		} else {
			$("#locationDes").html('定位失败');
		}
	}, {
		enableHighAccuracy : true
	})// 指示浏览器获取高精度的位置，默认false
};
// ==================图片=============================

$(document).on('click', '#fileclick', function() {
	return $("#file_upload").click();
});
$(document)
		.on(
				"change",
				"#file_upload",
				function() {
					var $file = $(this);
					var fileObj = $file[0];
					var windowURL = window.URL || window.webkitURL;
					var dataURL;
					var $img = $("#avatart");

					if (fileObj && fileObj.files && fileObj.files[0]) {
						dataURL = windowURL.createObjectURL(fileObj.files[0]);
						$img.attr('src', dataURL);
					} else {
						dataURL = $file.val();
						var imgObj = document.getElementById("preview");
						// 两个坑:
						// 1、在设置filter属性时，元素必须已经存在在DOM树中，动态创建的Node，也需要在设置属性前加入到DOM中，先设置属性在加入，无效；
						// 2、src属性需要像下面的方式添加，上面的两种方式添加，无效；
						imgObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
						imgObj.filters
								.item("DXImageTransform.Microsoft.AlphaImageLoader").src = dataURL;

					}
				});
// ===================回退按钮=========================
$(document).on(
		"click",
		"#backBtn",
		function() {
			var rejectMemo = $("#backReason").val();
			var param = {
				"rejectMemo" : rejectMemo
			};
			var eventId = $("#eventId").val();
			/*
			 * $.ajax({
			 * url:rootPath+"/ui/archive/backRegister/"+eventId+"?device=mobile&identify=",
			 * data:param, type:'get', dataType:'json',
			 * success:function(result){ if(result.code==1){ alert("回退成功");
			 * window.location.href=rootPath+"/ui/archive?device=mobile&identify="; } }
			 * 
			 * });
			 */

			$.ajaxFileUpload({
				url : rootPath + "/ui/archive/backRegister/" + eventId
						+ "?device=mobile&identify=",
				secureuri : false,// 是否需要安全协议
				fileElementId : 'file_upload',// 文件上传的Id属性
				dataType : 'text',
				data : param,
				success : function(result, status) {
					alert("回退成功");
					window.location.href = rootPath
							+ "/ui/archive?device=mobile&identify=";
				}
			});
			$("#backBtn").prop("disabled", "disabled");
			$("#popupView").popup("open");
		});